#include "wds_bullet_rocket.h"
#include "wds_sfx_manager.h"



WDSBulletRocket::WDSBulletRocket(float DamagePower, bool IsEnemyBullet) : 
									WDSBullet	(0.8f,
												false,
												DamagePower,
												WDSBullet::BULLET_TYPE_ROCKET),
									m_pSFX(NULL),
									m_bToGoForward(false)
{
	/*
	if(!IsEnemyBullet)
		Load("rocket_0001");
	else
		Load("rocket_0001_enemy");
		*/

	m_Acceleration = 0.5f;
	m_Speed = m_Movement.GetSpeed() * 0.25f;	
	m_Facing.SetCurrent(0);

}
	


void		WDSBulletRocket::Clear()
{
	if(m_pSFX)
		m_pSFX->ToDie();
	m_pSFX = NULL;
	WDSBullet::Clear();
}

void		WDSBulletRocket::Render(const math::Vec2& Offset,float Scale)
{
	if(!m_IsAlive)
	{
		return;
	}
	
	WDSBullet::Render(Offset,Scale);
}
	
void		WDSBulletRocket::RenderDebug(const math::Vec2& Offset,float Scale)
{
	WDSBullet::RenderDebug(Offset,Scale);
}
	
void		WDSBulletRocket::Tick(float dt,float SkillBulletSpeed, const math::Vec2& Offset)
{
	WDSBullet::Tick(dt,SkillBulletSpeed, Offset);
	m_Howlong = m_Sprite.m_SizeOriginal.y;
	

	if(m_Delay > 0)
		return;

	if(!m_IsAlive)
	{
		if(m_pSFX)
		{
			m_pSFX->ToDie();
			m_pSFX = NULL;
		}
		return;
	}

	

		const float MAX_SPEED = 3.0f;
		m_Speed += (m_Acceleration * dt); 
		if(m_Speed > MAX_SPEED)
			m_Speed = MAX_SPEED;

	m_Movement.SetMoveSpeed(m_Speed);
	
	SFXTick(dt);
	
}

void		WDSBulletRocket::SFXTick(float dt)
{
	if(m_pSFX)
		m_pSFX->FollowMe(GetPos() );
}

void		WDSBulletRocket::ReSpawn(		const math::Vec2& Pos,
											WDSBullet::STARTPOS StartDir,
											float Degree
											)
{
	
	// clean previous effect sfx
	if(m_pSFX)
	{
		m_pSFX->ToDie();
		m_pSFX = NULL;
	}
	WDSBullet::ReSpawn(Pos,StartDir,Degree);
	m_Speed = m_Movement.GetSpeed() * 0.25f;
	m_StartingPos = Pos;

	// Spawning smoke trail
	m_pSFX = WDSSFXManager::Instance().Spawn(WDSSfx::SFX_ROKETTRAIL, GetPos() ,1.0f);
	
}

void	WDSBulletRocket::OnHit(WDSLifeObject* pObj)
{
	WDSSFXManager::Instance().Spawn(WDSSfx::SFX_EXPLOSION_ROKET, GetPos(), 1.0f);
}

